package pit.com.ordermobilesystem.adapter;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import pit.com.ordermobilesystem.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class NewsAdapter extends BaseAdapter{
	JSONArray arrayNews;
	private Context mContext;
	  
	public NewsAdapter(JSONArray arrayStores, Context mContext) {
		super();
		this.arrayNews = arrayStores;
		this.mContext = mContext;
	}

	@Override
	public int getCount() {
		return arrayNews.length();
	}

	@Override
	public Object getItem(int position) {
		try {
			return arrayNews.get(position);
		} catch (JSONException e) {
			
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView==null){
			LayoutInflater li = (LayoutInflater)mContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView=li.inflate(R.layout.view_row_news, null, true);
		}else{
			
		}
		JSONObject store=(JSONObject) getItem(position);
		TextView tv_title=(TextView) convertView.findViewById(R.id.tv_title);
		TextView tv_description=(TextView) convertView.findViewById(R.id.tv_description);
		ImageView img_view=(ImageView) convertView.findViewById(R.id.img_item);
		try {
			tv_title.setText(store.getString("news_title"));
			tv_description.setText(store.getString("news_content"));
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return convertView;
	}



}
